#!/bin/bash

# Script to run the test suites under all possible combinations of g++/python/params.
# Note that this script is NOT intended to be portable NOR general use.

cd ..

LOG=/tmp/test_distribution.log
RED="\033[01;31m"
GREEN="\033[01;32m"
RESET="\033[00;00m"
FAIL=$RED"FAIL"$RESET
OK=$GREEN"OK"$RESET

date > $LOG
echo >> $LOG

for CXX1 in /usr/bin/g++?* ; do

    for OPTS1 in " --enable-optim" "--disable-optim"; do

	for PYTHON in /usr/bin/python?.? ; do

	    echo -ne "SRC("$(basename $CXX1)", $OPTS1, "$(basename $PYTHON)"): "

	    PYTHON_VER=$(basename $PYTHON | cut -f2 -d'n')

	    # compile src
	    if ! ( CXXFLAGS=-Werror CXX=$CXX1 ./configure $OPTS1 --with-python=$PYTHON_VER >> $LOG &&
		    echo -n "conf " &&
		    make -C src clean all >> $LOG ) ; then
		echo -e $FAIL
		exit 1
	    fi
	    echo "make"

	    for CXX2 in /usr/bin/g++?* ; do

		for OPTS2 in " --enable-optim" "--disable-optim"; do

		    echo -ne "\tTEST("$(basename $CXX2)", $OPTS2):   "

		    # compile tests
		    if ! ( CXXFLAGS=-Werror CXX=$CXX2 ./configure $OPTS2 --with-python=$PYTHON_VER >> $LOG &&
			    echo -n "conf " &&
			    make -C test clean all >> $LOG ) ; then
			echo -e $FAIL
			exit 1
		    fi

		    echo -n "make "

		    # test suite
		    cd test
		    if ! $PYTHON python_test_suite.py 1 $LOG >& /dev/null ||
		       ! $PYTHON python_test_suite.py 100 >& /dev/null ; then
			echo -e $FAIL
		    else
			echo -e "test_suite "$OK
		    fi
		    cd ..

		done

	    done

	done

    done

done
